<template>
  <div>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <el-form-item>
          <el-input v-model="filters.keyword" placeholder="名牌名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="query">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleAdd">新增</el-button>
        </el-form-item>
      </el-form>
    </el-col>

<el-button type="text" @click="table = true">打开嵌套表格的 Drawer</el-button>
<el-drawer
    title="我嵌套了表格!"
    :visible.sync="table"
    direction="rtl"
    size="50%">
<el-table :data="gridData">
  <el-table-column property="date" label="日期" width="150"></el-table-column>
  <el-table-column property="name" label="姓名" width="200"></el-table-column>
  <el-table-column property="address" label="地址"></el-table-column>
</el-table>
</el-drawer>

<el-drawer
    title="我嵌套了 Form !"
    :before-close="handleClose"
    :visible.sync="dialog"
    direction="ltr"
    custom-class="demo-drawer"
    ref="drawer"
>
<div class="demo-drawer__content">
  <el-form :model="form">
    <el-form-item label="活动名称" :label-width="formLabelWidth">
      <el-input v-model="form.name" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="活动区域" :label-width="formLabelWidth">
      <el-select v-model="form.region" placeholder="请选择活动区域">
        <el-option label="区域一" value="shanghai"></el-option>
        <el-option label="区域二" value="beijing"></el-option>
      </el-select>
    </el-form-item>
  </el-form>
  <div class="demo-drawer__footer">
    <el-button @click="cancelForm">取 消</el-button>
    <el-button type="primary" @click="$refs.drawer.closeDrawer()" :loading="loading">{{ loading ? '提交中 ...' : '确 定' }}</el-button>
  </div>
</div>
</el-drawer>
    <div>
      <!--列表-->
      <el-table :data="dictionarytype" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
        <el-table-column type="selection" width="55">
        </el-table-column>
        <el-table-column type="index" width="60">
        </el-table-column>
        <el-table-column prop="name" label="产品" width="120" sortable>
        </el-table-column>
        <el-table-column prop="sn" label="产品编号" width="120" sortable>
        </el-table-column>
        <!--      <el-table-column prop="age" label="年龄" width="100" sortable>-->
        <!--      </el-table-column>-->
        <!--      <el-table-column prop="birth" label="生日" width="120" sortable>-->
        <!--      </el-table-column>-->
        <!--      <el-table-column prop="addr" label="地址" min-width="180" sortable>-->
        <!--      </el-table-column>-->
        <el-table-column label="操作" >
          <template scope="scope">
            <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
            <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!--编辑界面-->
    <!--    rules="editFormRules" ref="editForm"
    rules ：表单规则，  ref：为这里设置一个id引用 其他地方可以i直接引入
    -->
</div>

</template>

<script>
export default {
  data() {
    return {
      table: false,
      dialog: false,
      loading: false,
      gridData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }],
      dictionarytype: [],
      Empleoyee:[],
      total: 0, // 总条数
      currrentPage: 1, // 当前页
      size:5,//查询条数
      depts:[],
      listLoading: false,
      sels: [],//列表选中列
      title:'',
      editFormVisible: false,//编辑界面是否显示 // 编辑修改放一起使用
      editLoading: false,
      filters: {
        keyword: ''
      },
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      formLabelWidth: '80px',
      timer: null,
    };

  },
  methods: {
    // 查询按钮
    query(){
      this.currrentPage=1
      this.gettype()

    },
    //detal 删除
    //删除
    handleDel: function (index, row) {
      this.$confirm('确认删除该记录吗?', '提示', {
        type: 'warning'
      }).then(() => {
        //开启忙等框
        this.listLoading = true;
        this.$http.delete("/dept/"+row.id).then(result=>{
          result=result.data
          if (result.success){
            this.$message({
              message: '删除成功',
              type: 'success'
            });
            //删除成功设置
            //关闭忙等框 设置第一页并刷新
            this.listLoading = false;
            this.currrentPage=1,
                this.getDepartments();
          } else {
            this.$message({
              message: '删除失败',
              type: 'error'
            });
          }
        }).catch(result=>{
          // 取消什么都不做
        });
      }).catch(() => {

      });


      // this.$confirm('确认删除该记录吗?', '提示', {
      //   type: 'warning'
      // }).then(() => {
      //   this.listLoading = true;
      //   //NProgress.start();
      //   let para = { id: row.id };
      //   removeUser(para).then((res) => {
      //     this.listLoading = false;
      //     //NProgress.done();
      //     this.$message({
      //       message: '删除成功',
      //       type: 'success'
      //     });
      //     this.getDepartments();
      //   });
      // }).catch(() => {
      //
      // });
    },







    //删除
    handleDel: function (index, row) {
      this.$confirm('确认删除该记录吗?', '提示', {
        type: 'warning'
      }).then(() => {
        //开启忙等框
        this.listLoading = true;
        this.$http.delete("/dept/"+row.id).then(result=>{
          result=result.data
          if (result.success){
            this.$message({
              message: '删除成功',
              type: 'success'
            });
            //删除成功设置
            //关闭忙等框 设置第一页并刷新
            this.listLoading = false;
            this.currrentPage=1,
                this.getDepartments();
          } else {
            this.$message({
              message: '删除失败',
              type: 'error'
            });
          }
        }).catch(result=>{
          // 取消什么都不做
        });
      }).catch(() => {

      });

    },
    //获取列表
    gettype() {
      //  1.封装后端需要的参数
      let para = {
        currrentPage: this.currrentPage,
        size:this.size,
        // 分页查询的参数
        keyword: this.filters.keyword
      };
      // 2.开启忙加载框
      this.listLoading = true;
      // 3.发送ajax请求
      this.$http.post("/dic",para).then(result=>{
        console.log(result.data)
        //发送后关闭忙加载框
        this.listLoading=false;
        // console.log(result)
        result=result.data
        this.dictionarytype=result.row
        this.total=result.total
      }).catch(result=>{
        this.$message({
          message: '操作失败',
          type: 'error'
        });
      })
      //NProgress.start();
      // getUserListPage(para).then((res) => {
      //   this.total = res.data.total;
      //   this.Departments = res.data.Departments;
      //   this.listLoading = false;
      //   //NProgress.done();
      // });
    },
    handleClose(done) {
      if (this.loading) {
        return;
      }
      this.$confirm('确定要提交表单吗？')
          .then(_ => {
            this.loading = true;
            this.timer = setTimeout(() => {
              done();
              // 动画关闭需要一定的时间
              setTimeout(() => {
                this.loading = false;
              }, 400);
            }, 2000);
          })
          .catch(_ => {});
    },
    cancelForm() {
      this.loading = false;
      this.dialog = false;
      clearTimeout(this.timer);
    }
  },
  mounted() {
    setTimeout(()=>{
      //这里就写你要执行的语句即可，先让数据库的数据加载进去数组中你在从数组中取值就好了
      this.gettype();
    },800)
  }

}
</script>
<style scoped>

</style>
